jclass={
    initPage:function(){
        // 绑定dom对象
        this.obj = {
            searchText:$('#searchText'),
        };
        this.statesarr = ["路线偏移","路线超速","进入区域","离开区域","区域超速","区域超时","禁行时间"];

        // 声明全局变量
        this.data = {
            datatable:[],
            tableParams: {
                page:1,
                size:10,
                name: '',
                analyzeType: 3
            },
            dialogRuleTableParams: {
                id: '',
                page: 1,
                size: 5,
                isNot: 2, // 1已绑定2未绑定
                areaId: '',
                platformName: '',
                owersName: '',
                vehicleNo: '',
                transType: ''
            },
            dialogRowSelectList:[],
            dialogTableData: [],
            dialogAllcationParams: {
                settingId: '',
                carIds: '',
                addOrDel:2 // 2绑定 1解绑
            },
            map: {},
            mouseTool: {},
            overlays: [],
            drawTypeSelect: 'circle',
            tabSelectType: 3, // 1-路线偏移报警 2-路段限速报警 3-进入区域报警 4-离开区域报警 5-区域超速报警 6-区域超时报警
            addRuleParams: { // 添加规则参数
                name: '',
                settingType: '1',
                settingAreaId: '',
                fenceAreaId: '',
                startTime: '',
                endTime: '',
                analyzeType: '',
                maxSpeed: '',
                offsetWidth: '',
                remindingInterval: '',
                limitTime: '',
                createUserId: '',
                sounds: ''
            },
            selectTypeArr:[{val:'1',name:'自定义区域'},{val:'2',name:'行政区域'}],
            selectWlnameArr: []
        };
        this.getTableList();
        // this.creatTable({data:{},total:0});
        this.init();
        this.bindEvent();
    },
    init() {
        let that = this
        //十分年月日范围
        $('#J-datepicker').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            hide: function (type) {
                that.data.addRuleParams.startTime = this.$input.val()
                // that.data.addRuleParams.endTime = this.$input.eq(1).val()
            }
        });

        //十分年月日单个
        $('#datetime_start').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            hide: function (type) {
                that.data.addRuleParams.startTime = this.$input.val()
            }
        });
        $('#datetime_end').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            hide: function (type) {
                that.data.addRuleParams.endTime = this.$input.val()
            }
        });

        diquSelceted()
        // 重置
        $("#resetClick").click(() => {
            $("#search_name").val("")
        })

        // 查询
        $("#searchClick").click(() => {
            this.getTableList()
        })

    },
    bindEvent() {
        let that = this
        $("#jtab2 ul li").click(function(){
            let index = $(this).index();
            that.data.tabSelectType = $(this).data("type")
            $(this).addClass("active").siblings("li").removeClass("active");
            that.getTableList()
        })

        $("#add_dialog_submit").click(() => {
            let reg = /^[1-9]\d*$/
            if (!reg.test($("#d_input_time_interval").val())) {
                JPop.alert({msg:'时间必须大于0',type:'error'})
                return false
            }
            // console.log(obj)
            let dataform = $("#form_gz").serializeArray()
            let a = true
            console.log(dataform)
            dataform.forEach(item => {
                if(!item.value) a=false
            })
            if(a) {
                this.addSubmit()
                return false
            }
        })

        this.dialogBindHandler()
    },
    // 添加规则
    addSubmit() {
        this.data.addRuleParams.name = $("#d_input_name").val()
        this.data.addRuleParams.analyzeType = this.data.tabSelectType
        this.data.addRuleParams.settingAreaId = $("#dialog_type_subinput .item").eq(0).find("input").attr("data-id")
        this.data.addRuleParams.remindingInterval = $("#d_input_time_interval").val()
        this.data.addRuleParams.sounds = $("#d_input_sounds").val()

        this.data.addRuleParams.maxSpeed = $("#d_input_max_speed").val()
        this.data.addRuleParams.limitTime = $("#d_input_limit_time").val()
        this.data.addRuleParams.offsetWidth = $("#d_input_offset_width").val()

        console.log(this.data.addRuleParams)
        if (this.data.addRuleParams.id) {
            jrequest.put("/api/alarmAreaSetting",this.data.addRuleParams).then(res => {
                if(res) {
                    JPop.alert({msg:'修改成功！',type:'success'})
                    closeDialog()
                    this.getTableList()
                }
            })
        } else {
            jrequest.post("/api/alarmAreaSetting",this.data.addRuleParams).then(res => {
                if(res) {
                    JPop.alert({msg:'添加成功！',type:'success'})
                    closeDialog()
                    this.getTableList()
                }
            })
        }
        
    },
    getTableList() {
        let that = this
        this.data.tableParams.name = $("#search_name").val()
        this.data.tableParams.analyzeType = this.data.tabSelectType
        jrequest.get("/api/alarmAreaSetting",this.data.tableParams).then(res => {
            this.data.datatable = res.data
            if (Number(this.data.tabSelectType) === 1 || Number(this.data.tabSelectType) === 2) {
                $("#table_div").html("<table id='cnf_reportTable2'></table>")
                let columnsTwo = [
                    {
                        title : '序号',
                        align: "center",
                        formatter: function (value, row, index) {
                            //获取每页显示的数量
                            var pageSize=that.data.tableParams.size;
                            //获取当前是第几页
                            var pageNumber=that.data.tableParams.page;
                            //返回序号，注意index是从0开始的，所以要加上1
                            return pageSize * (pageNumber - 1) + index + 1;
                        }
                    },
                    {
                      field: "name",
                      title: "规则名称"
                    },
                    {
                      field: "createUserName",
                      title: "创建用户"
                    },
                    {
                      field: "fenceAreaName",
                      title: "线路名称"
                    },
                    {
                      field: "statusName",
                      title: "分配状态"
                    },
                    {
                      field: "createTime",
                      title: "创建时间"
                    },
                    {
                      field: "updateTime",
                      title: "更新时间"
                    },
                    {
                        field: 'Button',
                        title: '操作',
                        width: "220",
                        align: 'center',
                        events: operateEvents,
                    }
                ];
                this.setTableData("cnf_reportTable2",res,columnsTwo)
            } else if (Number(this.data.tabSelectType) === 7) {
                $("#table_div").html("<table id='cnf_reportTable3'></table>")
                let columnsThree = [
                    {
                        title : '序号',
                        align: "center",
                        formatter: function (value, row, index) {
                            //获取每页显示的数量
                            var pageSize=that.data.tableParams.size;
                            //获取当前是第几页
                            var pageNumber=that.data.tableParams.page;
                            //返回序号，注意index是从0开始的，所以要加上1
                            return pageSize * (pageNumber - 1) + index + 1;
                        }
                    },
                    {
                      field: "name",
                      title: "规则名称"
                    },
                    {
                      field: "startTime",
                      title: "开始时间"
                    },
                    {
                      field: "endTime",
                      title: "结束时间"
                    },
                    {
                      field: "createUserName",
                      title: "创建用户"
                    },
                    {
                      field: "createTime",
                      title: "创建时间"
                    },
                    {
                      field: "statusName",
                      title: "分配状态"
                    },
                    {
                        field: 'Button',
                        title: '操作',
                        width: "220",
                        align: 'center',
                        events: operateEvents,
                    }
                ];
                this.setTableData("cnf_reportTable3",res,columnsThree)
            } else {
                $("#table_div").html("<table id='cnf_reportTable'></table>")
                var columnsOne = [
                    {
                        title : '序号',
                        align: "center",
                        formatter: function (value, row, index) {
                            //获取每页显示的数量
                            var pageSize=that.data.tableParams.size;
                            //获取当前是第几页
                            var pageNumber=that.data.tableParams.page;
                            //返回序号，注意index是从0开始的，所以要加上1
                            return pageSize * (pageNumber - 1) + index + 1;
                        }
                    },
                    {
                      field: "name",
                      title: "规则名称"
                    },
                    {
                      field: "createUserName",
                      title: "创建用户"
                    },
                    {
                      field: "fenceAreaName",
                      title: "围栏名称"
                    },
                    {
                      field: "fenceAreaTypeName",
                      title: "围栏类型"
                    },
                    {
                      field: "statusName",
                      title: "分配状态"
                    },
                    {
                      field: "createTime",
                      title: "创建时间"
                    },
                    {
                      field: "updateTime",
                      title: "更新时间"
                    },
                    {
                        field: 'Button',
                        title: '操作',
                        width: "220",
                        align: 'center',
                        events: operateEvents,
                    }
                ];
                this.setTableData("cnf_reportTable",res,columnsOne)
            }
        })
    },
    // 得到数据塞表格
    setTableData(id, res,columns) {
        $(`#${id}`).bootstrapTable('destroy');
        this.tableEvent(id,res,columns,true);
        // $(`#${id}`).bootstrapTable('load',[]);
        // $(`#${id}`).bootstrapTable('append', res.data);
    },
    tableEvent:function(id,data,columns,paginationShow){
        data.data.forEach(item => {
            item.Button = this.operateFormatter()
        })
        let that = this
        $('#' + id).bootstrapTable({
            method: 'get',
            cache: false,
            height: 320,
            pagination: paginationShow,
            pageSize: that.data.tableParams.size,
            pageNumber:that.data.tableParams.page,
            striped: true,
            columns: columns,
            sidePagination: 'server', // client or server
            totalRows: data.total,
            data :data.data,
            onPageChange: function (size, number) {
                console.log(number)
                that.data.tableParams.page = number
                that.data.tableParams.size = size
                that.getTableList()
            },
            formatNoMatches: function(){
                return '暂无数据';
            }
        });
    },
    operateFormatter() {
        return [
            '<button type="button" id="table_gui">分配规则</button>',
            '<button type="button" id="table_edit">修改</button>',
            '<button type="button" id="table_del">删除</button>'
            
        ].join('');
    },
    // 判断是否有
    isRepeat(arrobj,obj) {
        let hash = {}
        for (let i in arrobj) {
            if (obj.id === arrobj[i].id) return true
        }
        return false
    },
    // 分配规则弹框
    getRuleDialog(selectRow) {
        $("#dialog_rule_allocation").show()
        $("#gz_dialog_subtitle").text(selectRow.name)
        $("#hy_type").prop("selectedIndex",-1)
        this.data.dialogRuleTableParams.id = selectRow.id
        this.getFenpeiGzTableList()
        
        // 表格操作 选择，取消选择，选择全部，取消选择全部
        $("#dialog_table").on('check.bs.table',(e,row,$element) => {
            if (this.isRepeat(this.data.dialogRowSelectList,row)) return
            this.data.dialogRowSelectList.push(row)
            $("#dialog_select_num").text(this.data.dialogRowSelectList.length)
        })
        $("#dialog_table").on('uncheck.bs.table',(e,row,$element) => {
            this.data.dialogRowSelectList = this.data.dialogRowSelectList.filter(item => row.id != item.id)
            $("#dialog_select_num").text(this.data.dialogRowSelectList.length)
        })
        $("#dialog_table").on('check-all.bs.table',() => {
            this.data.dialogRowSelectList = this.data.dialogTableData
            $("#dialog_select_num").text(this.data.dialogRowSelectList.length)
        })
        $("#dialog_table").on('uncheck-all.bs.table',() => {
            this.data.dialogRowSelectList = []
            $("#dialog_select_num").text(this.data.dialogRowSelectList.length)
        })
        this.data.dialogAllcationParams.settingId = selectRow.id
        // this.dialogBindHandler()

        this.selectedValue()
    },
    selectedValue:function(){
        let optionArr=[{name:"未分配",val:'2'},{name:"已分配",val:'1'}];
        this.creatId("#dialog_select_allcation",optionArr);
        let optionArr2=[{name:"全部",val:'-1'},{name:"班线客运",val:'1'},{name:"旅游包车",val:'2'},{name:"危险品运输",val:'3'}];
        this.creatId("#hy_type",optionArr2);
    },
    creatId:function(id,optionArr){
        $(id).html();
        var str="";
        $.each(optionArr,function (i) {
            str+="<option value='"+optionArr[i].val+"'>"+optionArr[i].name+"</option>"
        });
        $(id).html(str);
        $(id).comboSelect();
    },
    // 分配规则弹框列表
    getFenpeiGzTableList() {
        this.data.dialogTableData = []
        if ($(".d-search-div .item").eq(0).find("input").val()) {
            this.data.dialogRuleTableParams.areaId = $(".d-search-div .item").eq(0).find("input").attr("data-id")
        }
        this.data.dialogRuleTableParams.vehicleNo= $("#fp_dialog_search_vehicle_no").val()
        this.data.dialogRuleTableParams.platformName= $("#fp_dialog_search_platform_name").val()
        this.data.dialogRuleTableParams.owersName= $("#fp_dialog_search_owers_name").val()
        jrequest.get("/api/alarmAreaSetting/vehicle",this.data.dialogRuleTableParams).then(res => {
            this.data.dialogTableData = res.data
            $("#dialog_table").bootstrapTable('destroy');
            this.tableEventDialog(res)
            // $(`#dialog_table`).bootstrapTable('load',[]);
            // $(`#dialog_table`).bootstrapTable('append', res.data);
        })
    },
    tableEventDialog:function(data){
        let that = this
        $("#dialog_table").bootstrapTable({
            method: 'get',
            cache: false,
            height: 150,
            pagination: true,
            pageSize: that.data.dialogRuleTableParams.size,
            pageNumber:that.data.dialogRuleTableParams.page,
            striped: true,
            columns: [
                {
                    field: 'no',
                    title: '序号',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return index + 1;
                    }
                },
                {   field : 'checked',
                    checkbox: true,
                    width: "60"
                },
                {
                  field: "vehicleNo",
                  title: "车牌号码"
                },
                {
                  field: "transTypeName",
                  title: "行业类型"
                },
                {
                  field: "areaName",
                  title: "所属地区"
                },
                {
                  field: "platformName",
                  title: "所属运营商"
                },
                {
                  field: "owersName",
                  title: "所属企业"
                }
            ],
            sidePagination: 'server', // client or server
            totalRows: data.total,
            data :data.data,
            onPageChange: function (size, number) {
                console.log(number)
                that.data.dialogRuleTableParams.page = number
                that.data.dialogRuleTableParams.size = size
                that.getFenpeiGzTableList()
                $("#dialog_select_num").text(0)
                that.data.dialogRowSelectList = []
            },
            formatNoMatches: function(){
                return '暂无数据';
            }
        });
    },
    // 分配规则弹框事件
    dialogBindHandler() {
        let that = this
        // 分配弹框-select
        $("#dialog_select_allcation").change(function() {
            let val = $("#dialog_select_allcation option:selected").val()
            that.data.dialogAllcationParams.addOrDel = val
            that.data.dialogRuleTableParams.isNot = val
            if (val === "1") {
                $("#dialog_allocation").text("解绑")
                $("#dialog_allocation_all").text("全部解绑")
            } else if (val === "2") {
                $("#dialog_allocation").text("分配")
                $("#dialog_allocation_all").text("全部分配")
            }
        })

        $("#hy_type").change(function() {
            let val = $("#hy_type option:selected").val()
            that.data.dialogRuleTableParams.transType = val
            if(val == '-1') that.data.dialogRuleTableParams.transType = ''
        })

        $("#fp_dsearch").click(() => {
            // this.fpDialogtableReset()
            this.getFenpeiGzTableList()
        })

        $("#fp_dreset").click(() => {
            this.fpDialogReset()
        })

        // 分配
        $('#dialog_allocation').click((e) => {
            if (this.data.dialogRowSelectList && this.data.dialogRowSelectList.length) {
                this.allcationSumbit()
            } 
            e.stopPropagation()
        })
        // 全部分配
        $("#dialog_allocation_all").click(() => {
            this.data.dialogRowSelectList = this.data.dialogTableData
            this.allcationSumbit()
        })
    },
    // 分配
    allcationSumbit() {
        let carids = ''
        this.data.dialogRowSelectList.forEach(item => {
            carids += item.id + ","
        })
        this.data.dialogAllcationParams.carIds = carids.slice(0,-1)
        jrequest.post("/api/alarmAreaSetting/addSettingCar",this.data.dialogAllcationParams).then(res => {
            if(res.data) {
                closeRuleDialog()
                this.getTableList()
            }
        })
    },
    fpDialogReset() {
        this.data.dialogRuleTableParams.page = 1
        this.data.dialogRuleTableParams.size =  5
        this.data.dialogRuleTableParams.isNot = 2, // 1已绑定2未绑定
        this.data.dialogRuleTableParams.areaId = '',
        this.data.dialogRuleTableParams.platformName = '',
        this.data.dialogRuleTableParams.owersName = '',
        this.data.dialogRuleTableParams.vehicleNo = '',
        this.data.dialogRuleTableParams.transType = ""

        // this.data.dialogRowSelectList = []

        $("#fp_dialog_search_vehicle_no").val("")
        $("#fp_dialog_search_platform_name").val("")
        $("#fp_dialog_search_owers_name").val("")
        $("#hy_type").prop("selectedIndex",-1)
        $(".d-search-div .item").eq(0).find("input").val("")

        // $("#dialog_allocation").text("分配")
        // $("#dialog_allocation_all").text("全部分配")

        // $("#hytype_select_div input").val('全部')
        // $("#fp_select_div input").val('未分配')

        //  $("#dialog_select_num").text(0)
        this.fpDialogtableReset()
    },
    fpDialogtableReset() {
        this.data.dialogRowSelectList = []

        $("#dialog_allocation").text("分配")
        $("#dialog_allocation_all").text("全部分配")

        $("#hytype_select_div input").val('全部')
        $("#fp_select_div input").val('未分配')

        $("#dialog_select_num").text(0)
    }
}

$(function(){
    jclass.initPage();

    // 表格操作按钮
    window.operateEvents = {
        'click #table_del': (e,value,row,index) => {
            // console.log(row)
            

            // Jdialog.confirm({ message: `确定删除${row.name}?` }).on(function (e) {
            //     if (e) {
            //         jrequest.delete(`/api/alarmAreaSetting/${row.id}`,{}).then(res => {
            //             if (res.data.code === 0) {
            //                 jclass.getTableList()
            //             }
            //         })
            //     }
            // });
            JPop.dialogDel({msg:'确定删除?',operate:true}).on(success => {
                if (success) {
                    jrequest.delete(`/api/alarmAreaSetting/${row.id}`,{}).then(res => {
                        if (res.data.code === 0) {
                            jclass.getTableList()
                        }
                    })
                }
            })
        },
        'click #table_edit': (e,value,row,index) => {
            console.log(row)
            openDialog("edit",row)
        },
        'click #table_gui': (e,value,row,index) => {
            jclass.getRuleDialog(row)
        }
    }
});
function timeBlurHandler(id) {
    let val = $(id).val()
    let reg = /^[1-9]\d*$/
    if (!reg.test(val)) {
        JPop.alert({msg:'时间必须大于0',type:'error'})
    }
}
function dialogInitData(settingType,type,name) {
    type = type || ""
    name = name || ""
    if (settingType == '1') {
        initFenceList()
    } else {
        let areahtml = `<div class="item rtable_input" style="display:flex; width:308px;">
                <p><span style="color:#f00;">*</span>地区</p>
                <div class="box">
                    <div class="qrm-pinming">
                        <div class="qrm-input-border">
                            <input type="text" placeholder="请选择" class="qrm-input" style="margin-left: 0px;
                                background: none;
                                border: none;
                                border-radius: 0;
                                color: #fff;
                                width: inherit;">
                        </div>
                        <div class="qrm-main jdialog-qrm" id="stop_qrm_main"></div>
                    </div>
                </div>
            </div>`
        $("#dialog_type_subinput").html(areahtml)
        if (type === 'edit') {
            $("#dialog_type_subinput .item").eq(0).find("input").val(name)
        }
        // 地区下拉框
        diquSelceted();
    }
}
function openDialog(type,row) {
    // 1-路线偏移报警 2-路段限速报警 3-进入区域报警 4-离开区域报警 5-区域超速报警 6-区域超时报警
    type = type || "add"
    row = row || {}
    
    if (Number(jclass.data.tabSelectType) !== 7) { // 禁行时间外
        $("#not_7_row").html(`<div class="jdialog-row">
                    <p><span style="color:#f00;">*</span> 类型</p>
                    <div class="jdialog-select-div" id="dselect_type">
                    </div>
                </div>
                <div class="jdialog-row" id="dialog_type_subinput"></div>`)
        // <select style="width:195px;" id="dialog_type_select">
        //                 <option value="1">自定义区域</option>
        //                 <option value="2">行政区域</option>
        //             </select>
        jdSelect.JdSelectRadioInit("#dselect_type",jclass.data.selectTypeArr,(select) => {
            jclass.data.addRuleParams.settingType = select.val
            dialogInitData(select.val)
        })
        initFenceList()

        // $("#dialog_type_select").change(() => {
        //     let val = $("#dialog_type_select option:selected").val()
        //     jclass.data.addRuleParams.settingType = val
        //     dialogInitData(val)
        // })
        if (Number(jclass.data.tabSelectType) === 2 ||  Number(jclass.data.tabSelectType) === 5 
            || Number(jclass.data.tabSelectType) === 6 || Number(jclass.data.tabSelectType) ===1) {
            $("#dialog_bg_height").height(370)
        } else { 
            $("#dialog_bg_height").height(330)
        }
    } else {
        $("#not_7_row").html(``)
        $("#dialog_bg_height").height(240)
        jclass.data.addRuleParams.settingType = ''
    }
    if (Number(jclass.data.tabSelectType) === 2 ||  Number(jclass.data.tabSelectType) === 5) {
        $("#dialog_addrow").html(`<p><span style="color:#f00;">*</span> 最高速度</p>
                <input type="number" required name="maxsd" id="d_input_max_speed" class="input-note"><span class="input-note-span">km/h</span>`)
    } else if (Number(jclass.data.tabSelectType) === 6) {
        $("#dialog_addrow").html(`<p><span style="color:#f00;">*</span> 限制时间</p>
                <input type="text" required name="xztime" id="d_input_limit_time" class="input-note"><span class="input-note-span">分钟</span>`)
    } else if (Number(jclass.data.tabSelectType) === 1) {
        $("#dialog_addrow").html(`<p><span style="color:#f00;">*</span> 偏移宽度</p>
                <input type="number" required name="pl" id="d_input_offset_width" class="input-note"><span class="input-note-span" style="flex:0 0 79px;">米(50-999)</span>`)
    } else {
        $("#dialog_addrow").html(``)
    }

    if (type === "edit") {
        $("#dialog_title").text(`修改${jclass.statesarr[jclass.data.tabSelectType-1]}规则`)
        $("#d_input_name").val(row.name)
        $("#d_input_time_interval").val(row.remindingInterval)
        $("#d_input_sounds").val(row.sounds)
        // $("#dialog_type_select").find(`option[value=${row.settingType}]`).attr("selected",true)
        jdSelect.setSelectRadio("#dselect_type",jclass.data.selectTypeArr,row.settingType)

        // $("#d_input_starttime").val(row.startTime)
        // $("#d_input_endtime").val(row.endTime)
        // let st = moment('2019-8-30 14:00').format("YYYY-MM-DD HH:mm")
        // let et = moment('2019-8-29 13:00').format("YYYY-MM-DD HH:mm")

        let st = moment(row.startTime).format("YYYY-MM-DD HH:mm")
        let et = moment(row.endTime).format("YYYY-MM-DD HH:mm")
        $("#d_input_starttime").val(st)
        $("#d_input_endtime").val(et)

        $("#d_input_max_speed").val(row.maxSpeed)
        $("#d_input_limit_time").val(row.limitTime)
        $("#d_input_offset_width").val(row.offsetWidth)
        jclass.data.addRuleParams.id = row.id
        jclass.data.addRuleParams.fenceAreaId = row.fenceAreaId
        jclass.data.addRuleParams.startTime = row.startTime
        jclass.data.addRuleParams.endTime = row.endTime

        if (row.settingType == 1) {
            initFenceList("edit",row.fenceAreaId)
        } else if (row.settingType == 2) {
            jclass.data.addRuleParams.settingAreaId = row.settingAreaId
            
            dialogInitData(row.settingType,"edit",row.settingAreaName)
        }
        

    } else {
        $("#dialog_title").text(`添加${jclass.statesarr[jclass.data.tabSelectType-1]}规则`)
        jclass.data.addRuleParams.id = ''
    }

    $("#stopAddDialog").show()

}
// h设置弹框中 围栏名称的列表
function initFenceList(type,id) {
    type = type || ''
    id = id || ''
    $("#dialog_type_subinput").html(`<p><span style="color:#f00;">*</span> 围栏名称</p>
        <div class="jdialog-select-div" id="dselect_wlname"></div>`)
    // <select style="width:195px;" id="dialog_fence_select"></select>
    jrequest.get("/api/fenceArea",{}).then(res => {
        // let optionstr = ''
        // res.data.forEach(item => {
        //     optionstr += `<option value=${item.id}>${item.name}</option>`
        // })
        res.data.forEach(item => {
            item.val = item.id
        })
        jclass.data.selectWlnameArr = res.data
        jclass.data.addRuleParams.fenceAreaId = jclass.data.selectWlnameArr[0].val
        jdSelect.JdSelectRadioInit("#dselect_wlname",jclass.data.selectWlnameArr,(select) => {
            jclass.data.addRuleParams.fenceAreaId = select.val
        })
        // $("#dialog_fence_select").html(optionstr)
        if (type && type === 'edit') {
             jdSelect.setSelectRadio("#dselect_wlname",jclass.data.selectWlnameArr,id)
            // $("#dialog_fence_select").find(`option[value=${id}]`).attr("selected",true)
        }
        
    })
    // $("#dialog_fence_select").change(() => {
    //     let fenceId = $("#dialog_fence_select option:selected").val()
    //     jclass.data.addRuleParams.fenceAreaId = fenceId
    // })
}
function closeDialog() {
    $("#d_input_name").val("")
    $("#d_input_time_interval").val("")
    $("#d_input_sounds").val("")

    $("#d_input_starttime").val("")
    $("#d_input_endtime").val("")

    jclass.data.addRuleParams = { 
        name: '',
        fenceAreaId: '',
        startTime: '',
        endTime: '',
        analyzeType: '',
        maxSpeed: '',
        offsetWidth: '',
        remindingInterval: '',
        limitTime: '',
        createUserId: '',
        sounds: ''
    }

    $("#stopAddDialog").hide()
}
function closeRuleDialog() {
    $("#dialog_rule_allocation").hide()
    jclass.fpDialogReset()
}

/**
 * 请求地区数据
 * */
function diquSelceted() {
    jrequest.get("/api/assessMent/selectByArea",{}).then(res => {
        let data = res.data
        data[0].code = 1;
        $.each(data[0].cityAreaVOS, function(i, dom) {
            data[0].cityAreaVOS[i].code = 2;
            $.each(data[0].cityAreaVOS[i].cityAreaVOS, function(j, dom) {
                data[0].cityAreaVOS[i].cityAreaVOS[j].code = 3;
            })
        })
        this.creatMainRido("stop_qrm_main", data, "cityAreaVOS", "code");
    })
}
/**
 * 下拉框
 * */
function creatMainRido(id, attr, child, jibie) {
    $(id).html("");
    var sttrdiv = "";
    for(var i = 0; i < 3; i++) {
        sttrdiv += "<div class='qrm-border" + (i + 1) + "' style='display:none'>" +
            "<ul class='qrm-lev-" + (i + 1) + " qrm-lev' id='qrm-border1'>" +
            "</ul>" +
            "</div>"
    };
    $(".qrm-main").html(sttrdiv);
    var str = "";
    $("#qrm-border1").html("");
    var forTree = function(o) {
        for(var i = 0; i < o.length; i++) {
            var urlstr = "";
            try {
                urlstr = "<li><span data-id='" + o[i]["id"] + "'>" + o[i]["name"] + "</span><i class='qrm-arrow-right'></i><ul class='li-zi-" + o[i][jibie] + "' style='display: none'>";
                str += urlstr;
                if(o[i][child] != null) {
                    forTree(o[i][child]);
                }
                str += "</ul>";
            } catch(e) {}
        }
        return str;
    };
    $("#qrm-border1").html(forTree(attr));
}

